Wednesday 3 March 2021

failing

at good enough scientific practice in R

more failures than success

For every \(\varphi\) successes, there are \(\theta\) failures.

Proportion of success

\[ \frac{\varphi}{\varphi + \theta} \]

All trials

\[ \varphi + \theta \]

We often think of science as a function of success

\[ \varphi \sim \text{Binomial}\left( \varphi + \theta,\, \frac{\varphi}{\varphi + \theta}\right) \]

today, let’s talk about \(\theta\)

standard structure

phd in statistical science

\(\color{darkgreen}{\text{mathematics}}\) \(\to\)

code \(\to\)

paper \(\to\)

tool

failing at all the things

the nature of interdisciplinary research

\(\color{darkred}{\times}\) mathematics \(\not\to\)

\(\color{darkred}{\times}\) code \(\not\to\)

\(\color{darkred}{\times}\) paper \(\not\to\)

\(\color{darkred}{\times}\) tool

Good enough scientific programming

CRAPL

the Community Research and Academic Programming License

An open source license for academics has additional needs:

  1. it should require that source and modifications used to validate scientific claims be released with those claims; and
  2. more importantly, it should absolve authors of shame, embarrassment and ridicule for ugly code.

Recommended by @DrVeronikaCH whose How I Fail blog is well worth checking out.

failing is the best we can do

at reproducible science

reproducible scientific analysis in R

## # A tibble: 6 x 1
##   sections_in_this_talk                    
##   <chr>                                    
## 1 **.Rmd**-driven development              
## 2 **functions**                            
## 3 **documentation** of functions           
## 4 **git** and version control              
## 5 **testing** of functions and data        
## 6 reproducible **document** for publication

reproducible scientific analysis in R

sections

.Rmd-driven development

functions

documentation of functions

git and version control

testing of functions and data

reproducible document for publication

for each section

  1. my fails
  2. key resources
  3. your fails

.Rmd-driven development

failing at

.Rmd-driven development

Suppose we’re interested in the 5 most frequent observations in farming production systems considered in this 1072, 84 systematic review.

## # A tibble: 3 x 4
##   short_title  farmingproduction… farmingproductio… farmingproductio…
##   <chr>        <chr>              <chr>             <chr>            
## 1 Aaron (2005) <NA>               <NA>              <NA>             
## 2 Aavik (2008) Livestock          <NA>              Cropped fields (…
## 3 Aavik (2010) <NA>               <NA>              <NA>

These data can be analysed and formatted nicely in document.

bufferstrips %>%
    select(short_title,
         contains("farmingproduction")) %>%
    pivot_longer(
        cols = contains("farming"),
        names_to = "production_system",
        values_to = "system_value",
        values_drop_na = TRUE
    ) %>%
    separate(col = production_system,
             into = c("farming", "system")) %>%
    filter(system_value != "Not described",
           !str_detect(system_value, "Other")) %>%
    count(system) %>%
    arrange(desc(n)) %>%
    head(5) %>%
    gt()
system n
croppedfields 738
croppedfieldsinfo 445
livestock 199
grassland 107
livestockinfo 92

some helpful resources

.Rmd-driven development

Some Useful Resources
.Rmd
Item Type Author Title Date Topic
blogPost Riederer, Emily 2019-05-04 .Rmd
book Grolemund, Yihui Xie, J. J. Allaire, Garrett 2020 .Rmd
This is not intended to be a definitive list; these are the resources that helped me the most when I was failing at .Rmd. Share the resources that worked for you via @R-Ladies Freiburg on twitter, or in the chapter's slack group.

.Rmd fails

tell me your stories

git

failing

at git

working on your own

Set up with Happy Git to R

Create repository on GitHub

# pr helpers

pr_init(branch = "idea")

# make changes

# commit

pr_push()

# wait for merge

pr_finish()

resources

git

Some Useful Resources
git
Item Type Author Title Date Topic
book Bryan, Jennifer 2019 git
journalArticle Bryan, Jennifer 2018-01-02 git
book various 2021 git
book various 2021 git
This is not intended to be a definitive list; these are the resources that helped me the most when I was failing at git. Share the resources that worked for you via @R-Ladies Freiburg on twitter, or in the chapter's slack group.

git fails

tell me your stories

functions

function fails

tell me your stories

documentation

document fails

tell me your stories

testing

testing fails

tell me your stories

manuscript

reproducible manuscript fails

tell me your stories

unexpected

failing is the best we can do

at reproducible science

If you failed, it means you tried.

You’ll never get everything right in computational science.

Trying is the best you can do. You will fail. You find useful workflows.

references